package com.wk.wechattool.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.wk.wechattool.R;
import com.wk.wechattool.bean.MyEvenBusBean;
import com.wk.wechattool.icallback.OnItemClickCallBack;

import java.util.List;


public class FunctionAdapter extends RecyclerView.Adapter {
    private List<MyEvenBusBean> list;
    private Context context ;
    private OnItemClickCallBack onItemClickCallBack ;

    public FunctionAdapter(Context context, List<MyEvenBusBean> list , OnItemClickCallBack onItemClickCallBack)  {
        this.context=context ;
        this.list = list;
        this.onItemClickCallBack=onItemClickCallBack ;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)  {
        LayoutInflater mInflater= LayoutInflater.from(context);
        return new MyViewHolder( mInflater.inflate(R.layout.list_item_lay, parent, false));
    }


    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position)  {
        final MyViewHolder viewHolder = (MyViewHolder) holder;
        String  bean = list.get(position).getNameInfo() ;
        viewHolder.functionType.setText( bean );
    }


    @Override
    public int getItemCount()  {
        return list != null ? list.size() : 0;
    }


    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView functionType;

        MyViewHolder(View itemView) {
            super(itemView);
            functionType = (TextView) itemView;

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int index = getAdapterPosition() ;
                    onItemClickCallBack.onItemClick( index );
                }
            });

        }
    }

}
